import type { Response } from "@/interface/Response";
import { Request } from "./request";

const DefaultUrlKey = "local";

export const HttpConfig = {
  local: "http://localhost:5045/api/",
  remote: "",

  GetUrl: (): string => {
    return HttpConfig[DefaultUrlKey];
  },
};

export class Http {
  ControllerName: string;
  constructor(ControllerName: string) {
    this.ControllerName = ControllerName + "/";
  }
  Post<T>(MethodName: string, data?: T): Promise<Response.ApiReqsult> {
    return Request(
      HttpConfig.GetUrl() + this.ControllerName + MethodName,
      "POST",
      data
    );
  }
  Get<T>(MethodName: string, data?: T): Promise<Response.ApiReqsult> {
    return Request(
      HttpConfig.GetUrl() + this.ControllerName + MethodName,
      "GET",
      data
    );
  }
}
